import request from '@/utils/request'

export function getAllCategory() {
  var curCategories = []
  request({
    url: '/categories',
    method: 'get'
  }).then((res) => {
    var allTheme = res.data.data.allTheme

    for (const Theme of allTheme) {
      var curTheme = {
        label: '',
        children: [],
        type: 'Theme',
        isChoosed: false,
        value: '',
        show: true
      }
      curTheme.label = Theme.themeName
      curTheme.value = Theme.themeName
      for (const category of Theme.categoryVos) {
        var curCategory = {
          label: '',
          type: 'Category',
          isChoosed: false,
          value: '',
          show: true
        }
        curCategory.label = category
        curCategory.value = category
        curTheme.children.push(curCategory)
      }
      curCategories.push(curTheme)
    }
  })
  return curCategories
}

export function createNewCategory(category, theme) {
  return request({
    url: '/categories/' + category + '/' + theme,
    method: 'get'
  })
}
export function deleteCategory(category) {
  return request({
    url: '/categories/' + category,
    method: 'delete'
  })
}
export function deleteTheme(theme) {
  return request({
    url: '/theme/' + theme,
    method: 'delete'
  })
}
export function createNewCategoryOnly(category) {
  return request({
    url: '/categories/add/' + category,
    method: 'get'
  })
}
export function updateCategory(oldCategory, newCategory) {
  return request({
    url: '/categories/' + oldCategory + '/' + newCategory,
    method: 'put'
  })
}
export function updateTheme(oldTheme, newTheme) {
  return request({
    url: '/theme/' + oldTheme + '/' + newTheme,
    method: 'put'
  })
}
export function updateThemeToCategory(theme, category) {
  return request({
    url: 'updateThemeToCategory/' + theme + '/' + category,
    method: 'put'
  })
}
